Telegram Group & Telegram Channel
Что выведет этот код на Python?


def append_to(element, to=[]):
to.append(element)
return to

print(append_to(1))
print(append_to(2))
print(append_to(3, []))
print(append_to(4))


🔢 Варианты ответа:

A)

[2]
[3]
[4]


B)

[1, 2]
[3]
[1, 2, 4]


C)

[1, 2]
[1, 2, 3]
[1, 2, 3, 4]


D)

[1, 2]
[3]
[4]


Правильный ответ: B

💡 Почему?

В Python дефолтные аргументы вычисляются один раз — при определении функции.
Список
to=[] сохраняется и используется повторно, если явно не передан другой.
Поэтому
append_to(1), append_to(2) и append_to(4) работают с одним и тем же списком.



tg-me.com/python_job_interview/1070
Create:
Last Update:

Что выведет этот код на Python?


def append_to(element, to=[]):
to.append(element)
return to

print(append_to(1))
print(append_to(2))
print(append_to(3, []))
print(append_to(4))


🔢 Варианты ответа:

A)

[2]
[3]
[4]


B)

[1, 2]
[3]
[1, 2, 4]


C)

[1, 2]
[1, 2, 3]
[1, 2, 3, 4]


D)

[1, 2]
[3]
[4]


Правильный ответ: B

💡 Почему?

В Python дефолтные аргументы вычисляются один раз — при определении функции.
Список
to=[] сохраняется и используется повторно, если явно не передан другой.
Поэтому
append_to(1), append_to(2) и append_to(4) работают с одним и тем же списком.

BY Python вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_job_interview/1070

View MORE
Open in Telegram


Python вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

Traders also expressed uncertainty about the situation with China Evergrande, as the indebted property company has not provided clarification about a key interest payment.In economic news, the Commerce Department reported an unexpected increase in U.S. new home sales in August.Crude oil prices climbed Friday and front-month WTI oil futures contracts saw gains for a fifth straight week amid tighter supplies. West Texas Intermediate Crude oil futures for November rose $0.68 or 0.9 percent at 73.98 a barrel. WTI Crude futures gained 2.8 percent for the week.

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

Python вопросы с собеседований from ua


Telegram Python вопросы с собеседований
FROM USA